package common

import (
	"time"
	"fmt"
)


const (
	appid = "dcdc435cc4aa11e587bf0242ac1101de"
	hsot = "http://gw.yundzh.com"
	secretKey = "InsQbm2rXG5z"
	shortId = "00000010"
)

func GetToken() (string, error) {
	var token string
	var err error
	GetCache("dzhAccessToken", func(_cb func(data string)) {
		_cb(genToken())
	}, func(e error, res string) {
		token = res
		err = e
	})
	return token, err
}

func genToken() string {
	expiredTime := time.Now().Unix() + 24 * 3600
	rawMask := appid + "_" + fmt.Sprintf("%d", expiredTime) + "_" + secretKey
	hexMask := HmacSha1(rawMask, secretKey)
	token := fmt.Sprintf("%s:%d:%s", shortId, expiredTime, hexMask)
	return token
}